using System;
using System.Collections.Generic;
using UnityEngine;

namespace NodeCanvas.Variables
{
	[Serializable]
	public class BBVariableSet
	{
		[SerializeField]
		private string selectedTypeName;

		[SerializeField]
		private BBBool boolValue = new BBBool
		{
			value = true
		};

		[SerializeField]
		private BBFloat floatValue = new BBFloat();

		[SerializeField]
		private BBInt intValue = new BBInt();

		[SerializeField]
		private BBString stringValue = new BBString();

		[SerializeField]
		private BBVector2 vector2Value = new BBVector2();

		[SerializeField]
		private BBVector vectorValue = new BBVector();

		[SerializeField]
		private BBQuaternion quaternionValue = new BBQuaternion();

		[SerializeField]
		private BBColor colorValue = new BBColor();

		[SerializeField]
		private BBAnimationCurve curveValue = new BBAnimationCurve();

		[SerializeField]
		private BBGameObject goValue = new BBGameObject();

		[SerializeField]
		private BBComponent componentValue = new BBComponent();

		[SerializeField]
		private BBObject unityObjectValue = new BBObject();

		[SerializeField]
		private BBEnum enumValue = new BBEnum();

		private List<BBVariable> allVariables
		{
			get
			{
				List<BBVariable> list = new List<BBVariable>();
				list.Add(boolValue);
				list.Add(floatValue);
				list.Add(intValue);
				list.Add(stringValue);
				list.Add(vector2Value);
				list.Add(vectorValue);
				list.Add(quaternionValue);
				list.Add(colorValue);
				list.Add(curveValue);
				list.Add(goValue);
				list.Add(componentValue);
				list.Add(unityObjectValue);
				list.Add(enumValue);
				return list;
			}
		}

		public List<Type> availableTypes
		{
			get
			{
				List<Type> list = new List<Type>();
				foreach (BBVariable allVariable in allVariables)
				{
					if (allVariable is IMultiCastable)
					{
						list.Add((allVariable as IMultiCastable).baseType);
					}
					list.Add(allVariable.varType);
				}
				return list;
			}
		}

		public Blackboard bb
		{
			set
			{
				foreach (BBVariable allVariable in allVariables)
				{
					allVariable.bb = value;
				}
			}
		}

		public bool blackboardOnly
		{
			set
			{
				foreach (BBVariable allVariable in allVariables)
				{
					allVariable.blackboardOnly = value;
				}
			}
		}

		public Type selectedType
		{
			get
			{
				foreach (Type availableType in availableTypes)
				{
					if (selectedTypeName == availableType.ToString())
					{
						return availableType;
					}
				}
				return null;
			}
			set
			{
				selectedTypeName = ((value == null) ? null : value.ToString());
				foreach (BBVariable allVariable in allVariables)
				{
					IMultiCastable multiCastable = allVariable as IMultiCastable;
					if (multiCastable != null && multiCastable.baseType.NCIsAssignableFrom(value))
					{
						multiCastable.type = value;
					}
				}
			}
		}

		public BBVariable selectedBBVariable
		{
			get
			{
				foreach (BBVariable allVariable in allVariables)
				{
					if (allVariable.varType == selectedType)
					{
						return allVariable;
					}
				}
				return null;
			}
		}

		public object objectValue
		{
			get
			{
				if (selectedType != null)
				{
					return selectedBBVariable.objectValue;
				}
				return null;
			}
			set
			{
				if (selectedType != null)
				{
					selectedBBVariable.objectValue = value;
				}
			}
		}

		public override string ToString()
		{
			if (selectedBBVariable != null)
			{
				return selectedBBVariable.ToString();
			}
			return string.Empty;
		}
	}
}
